package Triangulation.oldMinimalityMetrics;

import java.util.List;

import datatypes.Edge;
import datatypes.IndexedFaceSet;
import datatypes.Triangle;

public abstract class OldAbstractMinimalityMetric implements OldMinimalityMetric {

	@Override
	public boolean localMinimumExistsForEdge(Edge edge, IndexedFaceSet set) {
		boolean foundLocalMinimum = false;
		
		// Get all the empty triangles adjacent to this particular edge.
		List<Triangle> trianglesLeft = edge.getTrianglesLeft();
		List<Triangle> trianglesRight = edge.getTrianglesRight();
		
		// To generate quads, we join each triangle with every other triangle, and test if
		// they are convex. If the triangles are on the same side, they won't be convex. We
		// scan through all quads around e to see if e is a local minimum for any of them
		checkingEdgeForLocalMinimality:
		for (Triangle triLeft: trianglesLeft) {
			
			for (Triangle triRight: trianglesRight) {		
				if (edgeIsLocallyMinimal(edge, triLeft, triRight)) {
					// If we find ANY local minimum for the edge e, it means that the edge
					// e remains a candidate, and cannot be removed
					foundLocalMinimum = true;
					break checkingEdgeForLocalMinimality; // jumps out of both loops.
				}
			}
		}
		return foundLocalMinimum;
	}

}
